﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Biosek
{
	public sealed class ByteArrayEqualityComparer : IEqualityComparer<byte[]>
	{
		static ByteArrayEqualityComparer _inst;
		public static ByteArrayEqualityComparer Instance
		{
			get
			{
				if (_inst == null) _inst = new ByteArrayEqualityComparer();
				return _inst;
			}
		}

		#region IEqualityComparer<byte[]> Members

		public bool Equals(byte[] r1, byte[] r2)
		{
			if (r1.Length != r2.Length) return false;
			for (int i = 0; i < r1.Length; i++)
			{
				if (r1[i] != r2[i]) return false;
			}
			return true;
		}

		public int GetHashCode(byte[] r)
		{
			int code = 0;
			foreach (var item in r)
			{
				code <<= 1;
				code ^= item;
			}
			return code;
		}

		#endregion
	}

}
